from PySide6.QtCore import Qt, QTime, Slot
from PySide6.QtWidgets import QDialog, QMessageBox

from Devices.Chiot.BsDevs.Plug.PlugDevice import PlugDevice
from Devices.Chiot.BsDevs.ComDev.Forms.ComTimerSetWindow import ComTimerSetWindow
from Devices.Chiot.BsDevs.Plug.Forms.TimerSetWindow_UI import Ui_FormTimerSetWindow

class TimerSetWindow(ComTimerSetWindow, QDialog):
    def __init__(self, parent = None):
        super().__init__()
        QDialog.__init__(self, parent)

        self._ui = Ui_FormTimerSetWindow()
        self._ui.setupUi(self)

        flags = self.windowFlags()
        self.setWindowFlags(flags & ~Qt.WindowContextHelpButtonHint)
    
    def GetTimerServices(self, timer):
        services = []
        services.append(PlugDevice.ServiceParams("switch", "on", self._ui.comboBox_timerSwitchCtrl.currentIndex()))
        timer.services = services
    
    def SetTimerServices(self, timer):
        for service in timer.services:
            if "switch" == service.serviceId:
                self._ui.comboBox_timerSwitchCtrl.setCurrentIndex(service.paraValue)
            else:
                MessageBoxFunc.ShowMessageBox("编辑定时器","未知的服务ID:%s" % (service.serviceId), self, QMessageBox.Critical)
        